<template>
  <view v-if="cart.length!==0">
    <my-address></my-address>
    <view class="cart-title">
      <uni-icons type="shop" size="18"></uni-icons>
      <text class="cart-title-text">购物车</text>
    </view>
    <view class="cart-info">




      <uni-swipe-action>
        <view class="cart-item" v-for="(goods,i) in cart" :key='i'>
          <uni-swipe-action-item :right-options="options" @click="swipeActionClickHandler(goods)">
            <my-goods :goods="goods" :show-radio="true" @radio-chang="radioChangHandler" :show-num="true"
              @num-change="numChangeHandler"></my-goods>
          </uni-swipe-action-item>
        </view>
      </uni-swipe-action>


    </view>
    <view class="cart-container">
      <my-settle></my-settle>
    </view>
  </view>
  <view class="null-box" v-else>
    <image src="/static/cart_box/null-cart.png"></image>
    <text class="null-text">空空如也~~</text>
  </view>
</template>

<script>
  import badgeMix from "@/mixins/tabbar-badge.js"
  import {
    mapState,
    mapMutations
  } from 'vuex'
  export default {
    computed: {
      ...mapState('m_cart', ['cart']),

    },
    mixins: [badgeMix],
    data() {
      return {
        options: [{
          text: '删除',
          style: {
            backgroundColor: '#C00000'
          }
        }]
      };
    },
    methods: {
      ...mapMutations('m_cart', ['updataGoodsState', 'updataGoodsCount', 'removeGoodsById']),

      radioChangHandler(e) {
        this.updataGoodsState(e)
      },
      numChangeHandler(e) {
        this.updataGoodsCount(e)
      },
      swipeActionClickHandler(goods) {
        this.removeGoodsById(goods)
      }
    }


  }
</script>

<style lang="scss">
  .cart-title {
    display: flex;
    height: 40px;
    align-items: center;
    padding-left: 5px;
    border-bottom: 1px solid #efefef;

    .cart-title-text {
      font-size: 14px;
      margin-left: 5px;
    }
  }

  .cart-container {
    padding-bottom: 50px;
  }

  .null-box {
    padding-top: 150px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;

    image {
      height: 100px;
      width: 100px;
    }
  }

  // .cart-info {
  //   margin: 5px 5px;

  //   .cart-item {
  //     display: flex;
  //     margin: 10px 0;
  //     border-bottom: 1px solid #efefef;

  //     .cart-item-left {
  //       image {
  //         width: 100px;
  //         height: 100px;
  //       }

  //     }

  //     .cart-item-right {
  //       margin-left: 5px;
  //       display: flex;
  //       flex-direction: column;
  //       justify-content: space-between;

  //       .item-name {
  //         font-size: 14px;
  //       }

  //       .cart-item-right-bm {
  //         display: flex;
  //         justify-content: space-between;

  //         .item-price {
  //           font-size: 16px;
  //           color: crimson;
  //         }

  //         .item-count {
  //           font-size: 16px;
  //         }
  //       }
  //     }
  //   }
  // }
</style>
